# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time

def test_chromedriver_for_pc():
    
    # 启动chromedriver
    chromedriver_path = "/home/shengyi/test/chrometest/chromedriver/chromedriver" # 指定ChromeDriver的路径
    service = Service(chromedriver_path)
    service.start() 

    # 建立会话
    options = Options()
    options.binary_location = "/home/shengyi/test/chrometest/chrome/chrome" # 指定Chrome浏览器的路径
    driver = webdriver.Remote(service.service_url, options=options)

    driver.get('https://www.linux.org/')
    time.sleep(3)

    driver.quit()

def test_chromedrvier_for_android():
    options = webdriver.ChromeOptions()
    options.add_experimental_option('androidPackage', 'com.android.chrome')

    chromedriver_path = "/home/shengyi/test/chromedriver_113/chromedriver"
    service = Service(chromedriver_path)
    driver = webdriver.Chrome(service=service, options=options)
    driver.get('https://www.linux.org/')

    driver.quit()


def test_chromedriver_options():
    options = webdriver.ChromeOptions()
    options.add_extension("extension.crx")
    options.set_capability("platformName", "Linux")

    # 命令行参数
    # 启动Chrome时就最大化
    options.add_argument("start-maximized")
    # 指定Chrome位置
    options.binary_location = "/path/to/chrome"

    dirver = webdriver.Chrome(options=options)

def test_chromedriver_desiredcapabilities():
    desire = webdriver.DesiredCapabilities.CHROME.copy()
    desire['platformName'] = "Linux"
    driver = webdriver.Remote(desired_capabilities=desire)

def test_chromedriver_capabilities_only_for_chrome():
    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    options.binary_location = "/path/to/chrome"
    options.add_extension("extension.crx")
    options.add_experimental_option("localState", {"key":"value"})
    options.add_experimental_option("prefs", {"key":"value"})
    options.add_experimental_option('detach', True)
    options.debugger_address = "127.0.0.1:38947"
    options.add_experimental_option("excludeSwitches", ['enable-automation'])
    options.add_experimental_option("minidumpPath", "/path/to/dumpfile")
    options.add_experimental_option("mobileEmulation", {"deviceName" : "emulator-5554"})
    options.add_experimental_option("perfLoggingPrefs", {"enableNetwork" : True})
    options.add_experimental_option("windowTypes", ["webview"])

